import { fileURLToPath, URL } from 'node:url'

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig(({command, mode})=>{
  let env = loadEnv(mode, process.cwd())
  return {
    plugins: [
      vue(),
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    build:{
      outDir: env.VITE_OUTPUT_DIR
    },
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/variable.scss";',
        }
      }
    },
    server:{
      proxy: {
        [env.VITE_APP_BASE_API]: {
          // 获取数据的服务器地址设置;
          target: env.VITE_SERVER_URL,
          // 是否跨域
          changeOrigin: true,
          // 路经重写.
          rewrite:(path) => path.replace(/^\/api/, ''),
        }
      }
    }
  }
})
